package com.noble.meether.ui.wallet.detail;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.noble.meether.R;
import com.noble.glamour.module.logic.baseui.ExBaseAdapter;
import com.noble.meether.ui.wallet.detail.bean.Income;

import java.util.List;

/**
 * Created by Su on 2018/6/13.
 */
public class WalletDetailAdapter extends ExBaseAdapter<Income> {

    public WalletDetailAdapter(Context context, List<Income> data) {
        super(context, data);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MyViewHolder holder;
        if (convertView == null) {
            convertView = inflate(R.layout.item_wallet_detail);
            holder = new MyViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (MyViewHolder) convertView.getTag();
        }
        final Income info = getItem(position);
        holder.item_title.setText(info.getTypeAmountName());
        holder.item_time.setText(info.getTimeCreate());
        holder.item_num.setText((info.isNegative() ? "-" : "+") + info.getAmount());
        holder.item_status.setVisibility(View.VISIBLE);

        String status = "已到账";
        if (info.getStatusPay() == -1) {
            status = "申请中";
        } else if (info.getStatusPay() == -2) {
            holder.item_status.setVisibility(View.GONE);
        }
        holder.item_status.setText(status);
        return convertView;
    }

    private class MyViewHolder {
        private TextView item_title, item_time, item_num, item_status;

        public MyViewHolder(View convertView) {
            initView(convertView);
        }

        private void initView(View convertView) {
            item_status = convertView.findViewById(R.id.item_status);
            item_title = convertView.findViewById(R.id.item_title);
            item_time = convertView.findViewById(R.id.item_time);
            item_num = convertView.findViewById(R.id.item_num);
        }
    }
}